--[array]
if table.getn == nil then 
    table.alength = function (state ) 
      return #state;
    end
else 
     table.alength = function (state ) 
      return table.getn(state);
    end
end

table.apush = function (state, t) 
    table.insert(state, t);
end

table.apop = function (state) 
   table.remove(state);
end
    
table.aunshift = function (state, value)
table.insert(state, 1, value)
end

table.ashift = function (state) 
      table.remove(state, 1);
end

table.asplice = function (state, index, many, item) 
      if many == -1 then 
        table.insert(state, index, item) ;
       else 
        table.remove(state, index);
      end
end

table.aslice = function  (state, s, e)
      local t = {};
      local len  = table.alength(state);
      local j  = s;
      local i  = 1;
      while j <= e do
          t[i] = state[j];
          i = i+1;
          j = j+1; 
      end
      return t;
end

table.aconcat =  function (state , arr)
    local len = table.alength(arr);
    local len2=table.alength(state) + 1;
    
    local start =  1;
    
    while start <= len do
        state[len2] = arr[start];
        start = start + 1
        len2  = len2 + 1
    end
    return state;
end

table.ajoin = function (state, fd) 
      return table.concat(state, fd);
end

table.eachIndex = function (state, func) 
     local len = table.alength(state);
     local i = 1;
     if func ~= nil then
          while i <= len do
                func(i, state[i]);
          end
     end
end

table.aindexOf = function (state, ele) 
    local len = table.alength(state) + 1;
    state [0] = ele;
    while ele ~= state[len] do
      len = len -1;
    end 
    return len;
end

table.asort = table.sort;



local exports={}

if table.getn == nil then 
    table.alength = function (state ) 
      return #state;
    end
else 
     table.alength = function (state ) 
      return table.getn(state);
    end
end

table.apush = function (state, t) 
    table.insert(state, t);
end

table.apop = function (state) 
   table.remove(state);
end
    
table.aunshift = function (state, value)
table.insert(state, 1, value)
end

table.ashift = function (state) 
      table.remove(state, 1);
end

table.asplice = function (state, index, many, item) 
      if many == -1 then 
        table.insert(state, index, item) ;
       else 
        table.remove(state, index);
      end
end

table.aslice = function  (state, s, e)
      local t = {};
      local len  = table.alength(state);
      local j  = s;
      local i  = 1;
      while j <= e do
          t[i] = state[j];
          i = i+1;
          j = j+1; 
      end
      return t;
end

table.aconcat =  function (state , arr)
    local len = table.alength(arr);
    local len2=table.alength(state) + 1;
    
    local start =  1;
    
    while start <= len do
        state[len2] = arr[start];
        start = start + 1
        len2  = len2 + 1
    end
    return state;
end

table.ajoin = function (state, fd) 
      return table.concat(state, fd);
end

table.eachIndex = function (state, func) 
     local len = table.alength(state);
     local i = 1;
     if func ~= nil then
          while i <= len do
                func(i, state[i]);
                i = i+1;
          end
     end
end

table.aindexOf = function (state, ele) 
    local len = table.alength(state) + 1;
    state [0] = ele;
    while ele ~= state[len] do
      len = len -1;
    end 
    return len;
end

table.asort = table.sort;

